<template>
  <div class="upload-container">
    <div class="title">
      合约模板上传
    </div>
    <div class="text-area">
      <el-input type="textarea" :rows="8" placeholder="输入参数" v-model="str"></el-input>
    </div>
    <div class="content">
      <el-upload ref="upload" action="" list-type="picture-card" :limit="1" :auto-upload="false" :on-change="handlePreview" :on-remove="handleRemove" :file-list="fileList">
        <i class="el-icon-plus"></i>
      </el-upload>
    </div>
    <el-button type="" @click="uploadFile">点击上传</el-button>
    <div class="result-msg">
      {{msg}}
    </div>
  </div>
</template>
<script>
import api from './api'
export default {
  data () {
    return {
      fileList: [],
      file: '',
      str: '',
      msg: ''
    }
  },
  methods: {
    uploadFile () {
      const param = new FormData()
      param.append('file', this.file.raw, this.file.name)
      param.append('request', this.str)
      console.log(param)
      api.uploadContractTemplate(param).then(res => {
        console.log(res, '上传结果')
        if (res.responseCode === '000000') {
          this.file = ''
          this.fileList = []
          this.msg = '上传成功！'
        } else {
          this.msg = '上传失败！'
        }
      }).catch(() => {
        this.file = ''
        this.fileList = []
        this.msg = '上传失败！'
      })
    },
    handleRemove (file, fileList) {
      this.file = ''
      this.fileList = []
    },
    // 校验excel是否符合规格
    handlePreview (file, fileList) {
      console.log(fileList)
      this.file = file
      this.fileList = [...fileList]
      return true
    }
  }
}
</script>

<style lang="less" scoped>
.upload-container{
  width: 100%;
  box-sizing: border-box;
  padding: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-flow: column;
  .title{
    font-size: 25px;
    margin-bottom: 30px;
  }
  .text-area{
    width: 60%;
    margin-bottom: 30px;
  }
  .content{
    margin-bottom: 50px;
  }
  .result-msg{
    font-size: 20px;
    font-weight: bold;
  }
}
</style>
